package com.anuo.app.modules.venue.controller;


import com.anuo.app.common.entity.Request;
import com.anuo.app.common.globalhandle.BaseController;
import com.anuo.app.common.utils.JsonUtil;
import com.anuo.app.modules.venue.entity.Venue;
import com.anuo.app.modules.venue.service.VenueService;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


@RestController
public class VenueController extends BaseController {
    @Autowired
    VenueService venueService;

    @PostMapping(value = "v1/apiSaveVenue", produces = {"application/json;charset=UTF-8"})
    public String apiSaveVenue(@RequestBody String encryptedReq) {
        //反序列化取得对象
        Request<Venue> req = JsonUtil.fromJson(encryptedReq,
                new TypeReference<Request<Venue>>() {
                });
        Venue venue = req.getEntities().get(0);
        venueService.saveVenue(venue);

        return rspSuccess();
    }

    @PostMapping(value = "v1/apiGetVenue", produces = {"application/json;charset=UTF-8"})
    public String apiGetVenue(@RequestBody String encryptedReq) {
        //反序列化取得对象
        Venue venue = getRequestObject(encryptedReq, new TypeReference<Request<Venue>>() {
        }).getFirstEntity();

        Venue result=venueService.getVenue(venue);
        if (result.getCreatedate() == null) {
            result.setCreatedate(new Date());
        }
        return rspSuccess(result);
    }




}